<template>
  <div>
    <!-- 零售单维护 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      selectionType="single"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog(1)">关 闭</el-button>
      <el-button type="primary" :disabled="isDisabled" @click="closeDialog(2)">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getEmployees, queryRetailOrder } from '@/api/dealerSale/SalesSanagement/ActualSalesChange';

export default {
  name: 'ActualSalesChange',
  mixins: [dictionary],

  data() {
    this.BaseTable = null;
    this.conf = { add: '新增', edit: '编辑', show: '明细' };
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryRetailOrder,
      fetchParams: {
        orderStatus: 60341008
      },
      isDisabled: true,
      saveData: []
    };
  },

  created() {
    this.queryEmployees();
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    // 查询销售顾问
    async queryEmployees() {
      const res = await getEmployees();
      if (res.resultCode == 200) {
        res.data.map(x => {
          this.topFilterList.find(item => item.fieldName == 'salesManId').itemList.push({ text: x.userName, value: x.userId });
        });
      }
    },
    // 搜索
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    closeDialog(type) {
      if (type == 1) {
        this.$emit('close', false);
      } else {
        this.$emit('close', false, this.saveData);
      }
    },
    selectChangeHandle(row) {
      if (row.length > 0) {
        this.isDisabled = false;
        this.saveData = row;
        return;
      }
      this.isDisabled = true;
    },
    createdFrom() {
      return [
        {
          type: 'SELECT',
          label: '销售顾问',
          fieldName: 'salesManId',
          placeholder: '请选择',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '零售单号',
          fieldName: 'orderNo',
          placeholder: '请输入'
        },
        {
          type: 'RANGE_DATE',
          label: '创建日期',
          fieldName: 'createStart|createEnd',
          placeholder: '请选择',
          initialValue: []
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '请输入'
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },

        {
          title: '零售单号',
          dataIndex: 'orderNo',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: []
        },
        {
          title: '订单状态',
          dataIndex: 'orderStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6034'),
          render: props => {
            return <span>{this.createDictText(props.row.orderStatus, '6034')}</span>;
          }
        },
        {
          title: '客户编号',
          dataIndex: 'customerNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: []
        },
        // {
        //   title: '大客户订单',
        //   dataIndex: 'isMajor',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList('1004'),
        //   render: props => {
        //     return <span>{this.createDictText(props.row.isMajor, '1004')}</span>;
        //   }
        // },
        // {
        //   title: '特殊订单',
        //   dataIndex: 'isSpecial',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList('1004'),
        //   render: props => {
        //     return <span>{this.createDictText(props.row.isSpecial, '1004')}</span>;
        //   }
        // },

        {
          title: '订单来源',
          dataIndex: 'orderSource',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6042'),
          render: props => {
            return <span>{this.createDictText(props.row.orderSource, '6042')}</span>;
          }
        },
        {
          title: '订单类型',
          dataIndex: 'orderType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6026'),
          render: props => {
            return <span>{this.createDictText(props.row.orderType, '6026')}</span>;
          }
        },
        {
          title: '创建时间',
          dataIndex: 'reportCreateDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配车时间',
          dataIndex: 'distributionDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '手机号',
          dataIndex: 'mobile',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '销售顾问',
          dataIndex: 'salesManName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '销售指导价',
          dataIndex: 'basicPrice',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '销售报价',
          dataIndex: 'salesQuatation',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '支付方式',
          dataIndex: 'payType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6015'),
          render: props => {
            return <span>{this.createDictText(props.row.payType, '6015')}</span>;
          }
        },
        {
          title: '定金金额',
          dataIndex: 'depositAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '定金日期',
          dataIndex: 'depositDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          align: 'center',
          width: 180,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品代码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          align: 'center',
          width: 400,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系名称',
          dataIndex: 'seriesName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型名称',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配置名称',
          dataIndex: 'packageName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '选装名称',
          dataIndex: 'optionName',
          align: 'center',
          width: 250,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '内饰',
          dataIndex: 'trimColorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '外饰',
          dataIndex: 'colorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '审批意见',
          dataIndex: 'checkDesc',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '审批人',
          dataIndex: 'checkPersonName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '审批时间',
          dataIndex: 'checkDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    }
  }
};
</script>
